﻿Public Class frmMenu

    Private Sub frmMenu_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        LoadMenu()
        LoadStatus()
    End Sub

    Private Sub LoadMenu()
        Dim sub_menu0, sub_menu1 As DevExpress.XtraBars.BarSubItem
        Dim btn_menu As DevExpress.XtraBars.BarButtonItem

        Dim myMenuF As New MenuF
        Dim myDtb As New DataTable
        myDtb = myMenuF.GetAll

        Dim sId0, sId1, sId2 As String
        Dim i, j, k As Integer

        'cap 1
        For i = 0 To myDtb.Rows.Count - 1
            sId0 = myDtb.Rows(i).Item("id")
            If sId0.Substring(2, 4) = "0000" Then
                sub_menu0 = New DevExpress.XtraBars.BarSubItem
                sub_menu0.Id = myDtb.Rows(i).Item("id")
                sub_menu0.Caption = myDtb.Rows(i).Item("caption")
                If myDtb.Rows(i).Item("user" + Project_UserType) = "0" Then sub_menu0.Enabled = False
                Me.Bar2.AddItem(sub_menu0)

                'cap 2
                For j = 0 To myDtb.Rows.Count - 1
                    sId1 = myDtb.Rows(j).Item("id")
                    If sId1.Substring(2, 2) <> "00" And sId1.Substring(4, 2) = "00" And sId1.Substring(0, 2) = sId0.Substring(0, 2) Then
                        If j + 1 <= myDtb.Rows.Count - 1 Then
                            If myDtb.Rows(j + 1).Item("id").ToString.Substring(2, 2) = sId1.Substring(2, 2) Then
                                sub_menu1 = New DevExpress.XtraBars.BarSubItem
                                sub_menu1.Id = myDtb.Rows(j).Item("id")
                                sub_menu1.Caption = myDtb.Rows(j).Item("caption")
                                sub_menu1.ImageIndex = myDtb.Rows(j).Item("image")
                                If myDtb.Rows(j).Item("user" + Project_UserType) = "0" Then sub_menu1.Enabled = False
                                sub_menu0.AddItem(sub_menu1)

                                'cap 3
                                For k = 0 To myDtb.Rows.Count - 1
                                    sId2 = myDtb.Rows(k).Item("id")
                                    If sId2.Substring(4, 2) <> "00" And sId2.Substring(2, 2) = sId1.Substring(2, 2) Then
                                        btn_menu = New DevExpress.XtraBars.BarButtonItem
                                        btn_menu.Id = myDtb.Rows(k).Item("id")
                                        btn_menu.Caption = myDtb.Rows(k).Item("caption")
                                        btn_menu.ImageIndex = myDtb.Rows(k).Item("image")
                                        If myDtb.Rows(k).Item("user" + Project_UserType) = "0" Then btn_menu.Enabled = False
                                        sub_menu1.AddItem(btn_menu)
                                    End If
                                Next
                            Else
                                btn_menu = New DevExpress.XtraBars.BarButtonItem
                                btn_menu.Id = myDtb.Rows(j).Item("id")
                                btn_menu.Caption = myDtb.Rows(j).Item("caption")
                                btn_menu.ImageIndex = myDtb.Rows(j).Item("image")
                                If myDtb.Rows(j).Item("user" + Project_UserType) = "0" Then btn_menu.Enabled = False
                                sub_menu0.AddItem(btn_menu)
                            End If
                        Else
                            btn_menu = New DevExpress.XtraBars.BarButtonItem
                            btn_menu.Id = myDtb.Rows(j).Item("id")
                            btn_menu.Caption = myDtb.Rows(j).Item("caption")
                            btn_menu.ImageIndex = myDtb.Rows(j).Item("image")
                            If myDtb.Rows(j).Item("user" + Project_UserType) = "0" Then btn_menu.Enabled = False
                            sub_menu0.AddItem(btn_menu)
                        End If

                    End If
                Next
            End If
        Next

        Me.Bar2.Reset()

    End Sub

    Private Sub LoadStatus()
        Me.BarStaticItem1.Caption = "  Tháng năm làm việc:  " + Project_UserType.ToString + "/" + Project_Nam.ToString
        Me.BarStaticItem2.Caption = "  Người sử dụng:  " + Project_UserType
        Me.BarStaticItem3.Caption = "  Ngày " + Date.Now.Day.ToString + " tháng " + Date.Now.Month.ToString + " năm " + Date.Now.Year.ToString.Trim + "  "

        Me.BarStaticItem1.AutoSize = DevExpress.XtraBars.BarStaticItemSize.Spring
        Me.BarStaticItem2.AutoSize = DevExpress.XtraBars.BarStaticItemSize.Spring
        Me.BarStaticItem3.AutoSize = DevExpress.XtraBars.BarStaticItemSize.Spring
    End Sub

    Private Sub BarManager_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarManager1.ItemClick
        Dim Id As Integer
        Id = e.Item.Id

        Select Case Id
            Case 10200 'he thong
                Dim f As New frmDoimatkhau
                f.ShowDialog()

            Case 10300
                Me.Close()
                Me.Hide()
                Dim f As New frmDangnhap
                f.ShowDialog()

            Case 10400
                Me.Close()

            Case 20100 'khoi tao
                If frmDanhMuc_TraCuu_Exists Then Exit Sub
                frmDanhMuc_TraCuu_Exists = True

                Project_Form = Me.Name
                Dim f As New frmDanhMuc_TraCuu
                f.MdiParent = _frmMenu
                f.Show()

            Case 20300 'khoi tao
                If frmDonVi_Exists Then Exit Sub
                frmDonVi_Exists = True

                Dim f As New frmDonVi
                f.MdiParent = _frmMenu
                f.Show()



                'Case 20200
                '    Dim f As New frmDanhPhap
                '    f.ShowDialog()

            Case 20400
                If frmLoaiChietTinh_Exists Then Exit Sub
                frmLoaiChietTinh_Exists = True

                Dim f As New frmLoaiChietTinh
                f.MdiParent = _frmMenu
                f.Show()

            Case 30100


        End Select
    End Sub

#Region "Button"
    Private Sub bbiChietTinh_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles bbiChietTinh.ItemClick
        If frmChietTinh_Exists Then Exit Sub
        frmChietTinh_Exists = True

        Project_Form = Me.Name

        Dim f As New frmChietTinh
        f.txtFormParent.EditValue = Me.Name
        f.MdiParent = _frmMenu
        f.Show()
    End Sub

    Private Sub bbiLapDuToan_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles bbiLapDuToan.ItemClick
        'If frmDuToan_CapNhat_Exists Then Exit Sub
        'frmDuToan_CapNhat_Exists = True

        'frmDuToan_CapNhat_AddEdit = "add"
        'Dim f As New frmDuToan_CapNhat
        'f.MdiParent = _frmMenu
        'f.Show()

        If frmDuToan_Exists Then Exit Sub
        frmDuToan_Exists = True

        Dim f As New frmDuToan
        f.MdiParent = _frmMenu
        f.Show()

    End Sub

    Private Sub bbiNghiemThu_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles bbiNghiemThu.ItemClick
        If frmNghiemThu_Exists Then Exit Sub
        frmNghiemThu_Exists = True

        Dim f As New frmNghiemThu
        f.MdiParent = _frmMenu
        f.Show()
    End Sub

    Private Sub bbiLapHoSoThiCong_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles bbiLapHoSoThiCong.ItemClick
        If frmThicong_Exists Then Exit Sub
        frmThicong_Exists = True

        Dim f As New frmThiCong
        f.txtFormParent.EditValue = Me.Name

        f.MdiParent = _frmMenu
        f.Show()
    End Sub


#End Region
    

    

    

  
End Class